// 从数组中删除重复项
const numbers = [1, 1, 20, 3, 3, 3, 9, 9];
const uniqueNumbers = [...new Set(numbers)]
console.log(uniqueNumbers);


//较短的 If-Else 的空合并
let maybeSomething;
// console.log(maybeSomething??"Nothing found")

//生成数字字母组成的随机数
Math.random().toString(16).substring(2);//'73529fc745c4d'
Math.random().toString(32).substring(2);//'ojq9oatp53g'


// 获取网页中使用了多少种标签
[...new Set([...document.querySelectorAll('*')].map(node=>node.tagName))].length;


// 数字金额转千分位
var num=1234567;
var num1=123456789.123456;

// useGrouping: false-->设置不加千分位
// minimumFractionDigits: 6 -->最小保留几位小数
// maximumFractionDigits: 2 -->最多保留几位小数
// minimumIntegerDigits: 8 -->整数部分最少保留几位，不够补0
// minimumSignificantDigits:8 -->有效数字的最小数目  
// maximumSignificantDigits:8 -->有效数字的最大数目
var formatNum=num.toLocaleString('en-US',{useGrouping: true,maximumFractionDigits: 2,minimumIntegerDigits: 11});
var formatNum1=num1.toLocaleString('en-US',{minimumFractionDigits: 2});
var formatNum2=num.toLocaleString('en-US',{minimumSignificantDigits:8});
var formatNum3=num.toLocaleString('en-US',{maximumSignificantDigits:6});
console.log(formatNum);
console.log(formatNum1);
console.log(formatNum2);
console.log(formatNum3);

//给字符串加后缀，贼好用
var a = 123456.6789
let b=a.toLocaleString(undefined, {style: 'decimal'}) //123,456.679
let c=a.toLocaleString(undefined, {style: 'percent'}) // 12,345,668%
let d=a.toLocaleString(undefined, {style: 'currency', currency: 'EUR'}) // €123,456.68
let e=a.toLocaleString(undefined, {style: 'currency', currency: 'CNY'}) // ¥123,456.68
let f=a.toLocaleString(undefined, {style: 'unit', unit: 'acre'}) // 123,456.679英亩
console.log(b,c,d,e,f);

//类数组对象转成数组
let likeArrObj={
    0:1,
    1:2,
    2:3,
    length:3
}
let arr1=Array.prototype.slice.call(likeArrObj) // [1, 2, 3]
let arr2=Array.prototype.slice.apply(likeArrObj)  // [1, 2, 3]
let arr3=Array.from(likeArrObj);  // [1, 2, 3]

//将rgb转化成16进制
const rgbToHex=(r,g,b)=>"#"+((1<<24)+(r<<16)+(g<<8)+b).toString(16).slice(1);
rgbToHex(255,255,254) //#fffffe

//获取16进制随机颜色
const randomHex=()=>`#${Math.floor(Math.random()*0xffffff).toString(16).padEnd(6,"0")}`;
randomHex()

let str=" 1 2 3 4 6 ";
String.prototype.trim=function(){
    return this.replace(/^\s+|\s+$/g,"");
}
console.log(str.trim());


//对象拷贝，以最后一个对象为准，没有则新增，有则覆盖
let ops = {
    serviceType: 'get',
    searchField: 'keyword',
    resultField: '',
    resultId: 'id',
    resultName: 'name',
    data: {},
}

let ops_copy={
    serviceType: 'post',
    searchField: 'regionName',
    resultName: 'objectDetailNameDesc',
    resultField: 'result',
    inputTarget: null,
}
Object.assign({}, ops, ops_copy)